<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索</legend>
            <div style="margin: 10px 10px 10px 10px" id="btn">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label" for="uid">用户ID</label>
                            <div class="layui-input-inline">
                                <!--注意此处input标签里的id-->
                                <input class="layui-input" id="uid" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" for="username">用户名</label>
                            <div class="layui-input-inline">
                                <!--注意此处input标签里的id-->
                                <input class="layui-input" id="username" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" for="nick">昵称</label>
                            <div class="layui-input-inline">
                                <!--注意此处input标签里的id-->
                                <input class="layui-input" id="nick" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" for="phone">电话</label>
                            <div class="layui-input-inline">
                                <!--注意此处input标签里的id-->
                                <input class="layui-input" id="phone" autocomplete="off">
                            </div>
                        </div>
                        </br>
                        <div class="layui-inline">
                            <label for="status" class="layui-form-label">状态</label>
                            <!--注意此处input标签里的id-->
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <!--注意此处input标签里的id-->
                                    <select id="status">
                                        <option value="0">全部</option>
                                        <option value="1">正常</option>
                                        <option value="2">禁用</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <!--注意此处button标签里的type属性-->
                            <button type="button" class="layui-btn layui-btn-primary data-search-btn"  lay-submit data-type="reload" lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            <button type="button" class="layui-btn"  id="exportBtn">导出数据</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <!--注意此处table标签里的id-->
        <table class="layui-table layui-hide" id="dataTable" lay-filter="dataTable"></table>
    </div>
</div>
{include file="block/layui" /}
<script type="text/html" title="修改" id="buttonTpl">
    <a href="{:url('edit')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-sm hisi-iframe" hisi-data="{width: '470px', height: '500px'}" title="修改">&nbsp;修改</a>
    <a href="{:url('del')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a>
</script>
<script type="text/html" id="statusTpl">
    <input type="checkbox" name="status" value="{{ d.status }}" lay-skin="switch" lay-filter="switchStatus" lay-text="正常|关闭" {{ d.status == 1 ? 'checked' : '' }} data-href="{:url('status')}?table=admin_language&id={{ d.id }}">
</script>

<script type="text/html" id="toolbar">
    <div class="layui-btn-group fl">
        <a href="{:url('add')}" class="layui-btn layui-btn-primary layui-btn-sm layui-icon layui-icon-add-circle-fine hisi-iframe" hisi-data="{width: '470px', height: '500px'}" title="添加">&nbsp;添加</a>
    </div>
</script>
<script type="text/javascript">
    layui.use(['table'], function() {
        var table = layui.table , $=layui.jquery , from= layui.from;
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter','exports']
            ,cols: [[ //表头
                {field: 'id', title: '用户ID' , width:'100'}
                ,{field: 'username', title: '用户名' , width:'100'}
                ,{field: 'nick', title: '昵称' , width:'100'}
                ,{field: 'portrait', title: '头像', templet:function(d){
                        return '<img src="'+"{:config('aly_config.oss_upload_url')}"+d.portrait+'" />';
                    } , width:'80' , height:'80'}
                ,{field: 'mobile', title: '电话' , width:'120'}
                ,{field: 'email', title: '邮箱' , width:'170'}
                ,{field: 'status', title: '状态', templet: '#statusTpl', width:'100'}
                ,{field: 'last_login_ip', title: '最后登录ip' , width:'100'}
                ,{field: 'last_login_time', title: '最后登录时间' , width:'120'}
                ,{field: 'ctime', title: '创建时间' , width:'120'}
                ,{field: 'mtime', title: '更新时间' , width:'120'}
                ,{title: '操作', templet: '#buttonTpl' , width:'120'}
            ]]
        });

        //以下是搜索框进行监测
        var active = {
            reload: function(){
                //执行重载
                table.reload('dataTable', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        uid:  $('#uid').val()  //在表格中进行搜索
                        ,username:  $('#username').val()		//在表格中进行搜索
                        ,nick:  $('#nick').val()		//在表格中进行搜索
                        ,phone:  $('#phone').val()		//在表格中进行搜索
                        ,status:  $('#status option:selected').val()		//在表格中进行搜索
                    }
                });
            }
        };

        $('.data-search-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('#exportBtn').on('click',function () {
            //使用ajax请求获取所有数据
            $.ajax({
                url:  '{:url("export")}' ,
                type: 'post',
                data: {
                    uid:  $('#uid').val()  //在表格中进行搜索
                    ,username:  $('#username').val()		//在表格中进行搜索
                    ,nick:  $('#nick').val()		//在表格中进行搜索
                    ,phone:  $('#phone').val()		//在表格中进行搜索
                    ,status:  $('#status option:selected').val()		//在表格中进行搜索
                },
                async: false,
                dataType: 'json',
                success: function (res) {
                    // table.exportFile('exportTable', res.data, 'xls');
                    table.exportFile(res.headers, res.data, 'xls');
                }
            });
        });

    });
</script>